/***************************************************************************
 *   Copyright (C) 2008 by Rysiek Krol,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "property.h"

#include <QSettings>

/**
* Konstruktor klasy
*/
Property::Property()
{
	this->keywords = new QSet<QString>();
    this->readProperty();

}

/**
* Destruktor Klasy
*/
Property::~Property()
{

delete this->keywords;
}

/**
* Zapisywanie Ustawien na dysku
*/
void Property::saveProperty()
{
    QSettings settings ( "AliceViewer", "AliceViewer" );
    settings.setValue ( "PictureDirectory",  this->pictureDir.absolutePath() );
    settings.setValue ( "ShowPictureScalled", this->showScalledPictures );
    settings.setValue( "WindowPosition", this->windowPosition);
    settings.setValue( "WindowSize", this->windowSize);
    settings.setValue( "IconSortingMethod", this->sortMethod);
    settings.setValue( "SlideShowJumpDelay", this->slideShowJumpTime);
    settings.setValue( "AutoSaveImage", this->getAutoSaveImages());

    QString keys;
    QSet<QString>::const_iterator iter;
    if (!this->keywords->isEmpty())
    {
        for (iter = this->keywords->constBegin(); iter !=this->keywords->end(); iter++)
        {
            keys.append(*iter);
            keys.append(",");
        }
    }
   settings.setValue("Keywords", keys);
}

/**
* Wczytywanie ustawie z dysku
*/
void Property::readProperty()
{
    QSettings settings ( "AliceViewer", "AliceViewer" );
    this->pictureDir = QDir(settings.value ( "PictureDirectory",QDir().absolutePath() ).value<QString>());
    this->showScalledPictures = settings.value ( "ShowPictureScalled", true ).toBool();
    this->windowPosition = settings.value("WindowPosition", QPoint(100, 100)).toPoint();
    this->windowSize = settings.value("WindowSize", QSize(1000, 800)).toSize();
    this->sortMethod = (Property::SortMethod) settings.value( "IconSortingMethod", Property::ByCommentDate).value<int>();
    this->slideShowJumpTime = settings.value("SlideShowJumpDelay", 4 ).value<short int>();
    this->setAutoSaveImages(settings.value ( "AutoSaveImage", false ).toBool());
    QString keys = settings.value("Keywords", "").toString();
	QStringList lista = keys.split(",", QString::SkipEmptyParts);
		QList<QString>::const_iterator i;
		for (i=lista.constBegin(); i != lista.constEnd(); i++){
			this->keywords->insert(*i);
		}
}



/**
* Zwraca parametr showScalledPictures odpowiedzialny za skalowanie obrazÃÂ³w.
*/
bool Property::getShowScalledPictures() const
{
    return showScalledPictures;
}

/**
* Ustawia parametr showScalledPictures]
* @param bool - jesli jest ustawiony na true obrazy mniejsze od wielkoÃÂci ekranu sÃÂ skalowane, jeÃÂli jest ustawiony na false, sa pokazywane w orginalnej rozdzielczosci
*/
void Property::setShowScalledPictures(bool theValue)
{
    if (theValue != this->showScalledPictures)
    {
        showScalledPictures = theValue;
        emit this->propertyChanged(Property::ShowScalledPicture);
    }
}

/**
* Zwraca domyÃÂlny katalog
* @return QDir
*/
QDir Property::getPictureDir() const
{
    return pictureDir;
}

/**
* Ustawia domyslny katalog
*/
void Property::setPictureDir(const QDir& theValue)
{
    pictureDir = theValue;
}


QSize Property::getWindowSize() const
{
    return windowSize;
}


void Property::setWindowSize(const QSize& theValue)
{
    windowSize = theValue;
}


QPoint Property::getWindowPosition() const
{
    return windowPosition;
}


void Property::setWindowPosition(const QPoint& theValue)
{
    windowPosition = theValue;
}


Property::SortMethod Property::getSortMethod() const
{
    return sortMethod;
}


void Property::setSortMethod(const Property::SortMethod& theValue)
{
    sortMethod = theValue;
}


short int Property::getSlideShowJumpTime() const
{
    return slideShowJumpTime;
}


void Property::setSlideShowJumpTime(const short int& theValue)
{
    slideShowJumpTime = theValue;
}


bool Property::getAutoSaveImages() const
{
    return autoSaveImages;
}


void Property::setAutoSaveImages ( bool theValue )
{
    autoSaveImages = theValue;
}


QFileInfo& Property::getCurrentItem()
{
    return currentItem;

}


void Property::setCurrentItem(QFileInfo theValue)
{
    currentItem = theValue;
}


QSet<QString>* Property::getKeywords() const
{
    return keywords;
}


void Property::setKeywords(QSet<QString>* theValue)
{
    keywords = theValue;
}
